import modelEntity from "./modelEntity";

export default class ApprovalProcess extends modelEntity {
  constructor(options) {
    super(options);
    this.Ref_Approval_Guid = options.Ref_Approval_Guid;
    this.Process_Index = options.Process_Index;
    this.Ref_Person_Guid = options.Ref_Person_Guid;
    this.Result = options.Result;
    this.Time = options.Time;
    this.Opinion = options.Opinion;
    this.personnelInfo = options.personnelInfo;
    this.personnelInfoName ="";
    if (this.personnelInfo){
      this.personnelInfoName = this.personnelInfo.Name;
    }
    this.canBeDelete = true;
  }
  get status() {   //单个过程的状态
    return this.Result == '同意' ? 'success' : this.Result == '驳回' ? 'error' : 'wait';
  }
  static newSubInstance() {
    return new ApprovalProcess({
      Ref_Approval_Guid: null,
      Process_Index: null,
      Ref_Person_Guid: null,
      Result: "",
      Time: null,
      Opinion: null,
    })
  }
  modify() {
    return new Promise((resolve, reject) => {
      getApp().globalData.api.http_put_json(`${getApp().globalData.baseUrl}/api/prj/approvalprocess?prj=` + getApp().globalData.nowPrj.GuidID, this)
        .then(
          res => {
            let model = new ApprovalProcess(res);
            resolve(model);
          }
        )
    })
  }
}
